var lishixianshi3={};//统计的3相同数的记录
var lishixindex3=0;//统计的3相同数的数量
var lishixianshi31={};//统计的3+1相同数的记录
var lishixindex31=0;//统计的3相同数的数量
var lishixianshi4={};//统计的4相同数的记录
var lishixindex4=0;//统计的4相同数的数量
var lishixianshi41={};//统计的4+1相同数的记录
var lishixindex41=0;//统计的4+1相同数的数量
var lishixianshi5={};//统计的5相同数的记录
var lishixindex5=0;//统计的5相同数的数量
var lishixianshi51={};//统计的5+1相同数的记录
var lishixindex51=0;//统计的5+1相同数的数量
var lishixianshi6={};//统计的6相同数的记录
var lishixindex6=0;//统计的6相同数的数量
var lishixianshi61={};//统计的6+1相同数的记录
var lishixindex61=0;//统计的6+1相同数的数量
var lishired,lishibule;//重置统计的相同数量

cc.Class({
    extends: cc.Component,

    properties: {
        lblmynum: {
            default: null,
            type: cc.Label
        },
        red1: {
            default: null,
            type: cc.Button
        },
        red2: {
            default: null,
            type: cc.Button
        },
        red3: {
            default: null,
            type: cc.Button
        },
        red4: {
            default: null,
            type: cc.Button
        },
        red5: {
            default: null,
            type: cc.Button
        },
        red6: {
            default: null,
            type: cc.Button
        },
        red7: {
            default: null,
            type: cc.Button
        },
        red8: {
            default: null,
            type: cc.Button
        },
        red9: {
            default: null,
            type: cc.Button
        },
        red10: {
            default: null,
            type: cc.Button
        },
        red11: {
            default: null,
            type: cc.Button
        },
        red12: {
            default: null,
            type: cc.Button
        },
        red13: {
            default: null,
            type: cc.Button
        },
        red14: {
            default: null,
            type: cc.Button
        },
        red15: {
            default: null,
            type: cc.Button
        },
        red16: {
            default: null,
            type: cc.Button
        },
        red17: {
            default: null,
            type: cc.Button
        },
        red18: {
            default: null,
            type: cc.Button
        },
        red19: {
            default: null,
            type: cc.Button
        },
        red20: {
            default: null,
            type: cc.Button
        },
        red21: {
            default: null,
            type: cc.Button
        },
        red22: {
            default: null,
            type: cc.Button
        },
        red23: {
            default: null,
            type: cc.Button
        },
        red24: {
            default: null,
            type: cc.Button
        },
        red25: {
            default: null,
            type: cc.Button
        },
        red26: {
            default: null,
            type: cc.Button
        },
        red27: {
            default: null,
            type: cc.Button
        },
        red28: {
            default: null,
            type: cc.Button
        },
        red29: {
            default: null,
            type: cc.Button
        },
        red30: {
            default: null,
            type: cc.Button
        },
        red31: {
            default: null,
            type: cc.Button
        },
        red32: {
            default: null,
            type: cc.Button
        },
        red33: {
            default: null,
            type: cc.Button
        },
        blue1: {
            default: null,
            type: cc.Button
        },
        blue2: {
            default: null,
            type: cc.Button
        },
        blue3: {
            default: null,
            type: cc.Button
        },
        blue4: {
            default: null,
            type: cc.Button
        },
        blue5: {
            default: null,
            type: cc.Button
        },
        blue6: {
            default: null,
            type: cc.Button
        },
        blue7: {
            default: null,
            type: cc.Button
        },
        blue8: {
            default: null,
            type: cc.Button
        },
        blue9: {
            default: null,
            type: cc.Button
        },
        blue10: {
            default: null,
            type: cc.Button
        },
        blue11: {
            default: null,
            type: cc.Button
        },
        blue12: {
            default: null,
            type: cc.Button
        },
        blue13: {
            default: null,
            type: cc.Button
        },
        blue14: {
            default: null,
            type: cc.Button
        },
        blue15: {
            default: null,
            type: cc.Button
        },
        blue16: {
            default: null,
            type: cc.Button
        },
    },


 
    suijishu:function(a,b){
        var mynum=new Array(a);
        var obj=new Array(a);
        var kai=0;
         /*
        *随机不相同的n个数
        */
        for (var i = 0, j = mynum.length; i < j; i++)
        {
           mynum[i]=Math.ceil(Math.random()*b);
           kai=0;
           for (var k = 0; k < j; k++)
           {
                if(obj[k]!=mynum[i]){ 
                    kai++;
                }			
                if(kai==a){
                    obj[i]=mynum[i];
                }
                if((kai<a)&&(k==(a-1))){
                    i--;
                }
            }
        }
        /*
        *排序随机出来的数字
        */
        function sequence(a,b){
            return a - b;
        }
        obj=obj.sort(sequence);
        return obj;//返回数组
    }, 
    onLoad () {
        this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
            //重置红球的颜色
            for(var k=1;k<=16;k++){
                var blue_tempstr="this.blue"+k+".node.color={a:255,b:255,g:255,r:255};";
                eval(blue_tempstr);
            }
            //重置蓝球的颜色
            for(var l=1;l<=33;l++){
                var red_tempstr="this.red"+l+".node.color={a:255,b:255,g:255,r:255};";
                eval(red_tempstr);
            }
        }, this);
        this.node.on(cc.Node.EventType.TOUCH_END, function (event) {
            cc.find("Canvas/lbl_jg").getComponent(cc.Label).string=2;
            var red=this.suijishu(6,33);//随机红球
            var blue=this.suijishu(1,16);//随机篮球
            //重置所有统计组和数
            lishixianshi3={};
            lishixindex3=0;
            lishixianshi31={};
            lishixindex31=0;
            lishixianshi4={};
            lishixindex4=0;
            lishixianshi41={};
            lishixindex41=0;
            lishixianshi5={};
            lishixindex5=0;
            lishixianshi51={};
            lishixindex51=0;
            lishixianshi6={};
            lishixindex6=0;
            lishixianshi61={};
            lishixindex61=0;
            lishired,lishibule;//重置统计的相同数量
            cc.loader.loadRes('ssqdate',function(err,ssqdate){
                if (err) {
                    cc.log(err);
                }
                for(var temp=0,k=ssqdate.json.shuju.length;temp<k;temp++){
                    var tongjired=0,tongjiblue=0;
                    lishired=ssqdate.json.shuju[temp].red;//赋值表格中的红球
                    lishibule=ssqdate.json.shuju[temp].blue;//赋值表格中的篮球
                    for(var i=0;i<red.length;i++){
                        for(var j=0;j<lishired.length;j++){
                            if(red[i]==lishired[j]){
                                tongjired+=1;//统计红球的相同数量
                            }
                        }
                    };
                    for(var i=0;i<blue.length;i++){
                        for(var j=0;j<lishibule.length;j++){
                            if(blue[i]==lishibule[j]){
                                tongjiblue+=1;//统计蓝球的相同数量
                            }
                        }
                    };
                    if(tongjired>=3){
                        switch(tongjired){
                            case 3:
                            if(tongjiblue==1){
                                //统计相同3+1的历史双色球组
                                lishixianshi31[lishixindex31]=lishired+"+"+lishibule;
                                lishixindex31++;
                            }else{
                                //统计相同3的历史双色球组
                                lishixianshi3[lishixindex3]=lishired+"+"+lishibule;
                                lishixindex3++;
                            }
                            break;
                            case 4:
                            if(tongjiblue==1){
                                //统计相同4+1的历史双色球组
                                lishixianshi41[lishixindex41]=lishired+"+"+lishibule;
                                lishixindex41++;
                            }else{
                                //统计相同4的历史双色球组
                                lishixianshi4[lishixindex4]=lishired+"+"+lishibule;
                                lishixindex4++;
                            }
                            break;
                            case 5:
                            if(tongjiblue==1){
                                //统计相同5+1的历史双色球组
                                lishixianshi51[lishixindex51]=lishired+"+"+lishibule;
                                lishixindex51++;
                            }else{
                                //统计相同5的历史双色球组
                                lishixianshi5[lishixindex5]=lishired+"+"+lishibule;
                                lishixindex4++;
                            }
                            break;
                            case 6:
                            if(tongjiblue>=1){
                                //统计相同6+1的历史双色球组
                                lishixianshi61[lishixindex61]=lishired+"+"+lishibule;
                                lishixindex61++;
                            }else{
                                //统计相同6的历史双色球组
                                lishixianshi6[lishixindex6]=lishired+"+"+lishibule;
                                lishixindex6++;
                            }
                            break;
                        }
                    };
                }
                //输出统计到历史相同数
                cc.find("Canvas/lbllishi").getComponent(cc.Label).string="3:"+lishixindex3+"--3+1:"+lishixindex31+"--4:"+lishixindex4+"--4+1:"+lishixindex41+"--5:"+lishixindex5+"--5+1:"+lishixindex51+"--6:"+lishixindex6+"--6+1:"+lishixindex61;
            });
            
            this.lblmynum.string=red+"+"+blue;
            //修改随机到的蓝球的颜色
            for(var i=0;i<blue.length;i++){
                var blue_str="this.blue"+blue[i]+".node.color={a:255,b:255,g:0,r:255};";
                eval(blue_str);
            }
            //修改随机到的红球的颜色
            for(var j=0;j<red.length;j++){
                var red_str="this.red"+red[j]+".node.color={a:255,b:255,g:0,r:255};";
                eval(red_str);
            }
        }, this);
    },

    // update: function (dt) {
    // },
});
